package cc.booku.owlbox.BottomBar;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaychan.library.BottomBarItem;
import com.chaychan.library.BottomBarLayout;
import com.timmy.tdialog.TDialog;
import com.timmy.tdialog.base.BindViewHolder;
import com.timmy.tdialog.listener.OnBindViewListener;
import com.timmy.tdialog.listener.OnViewClickListener;

import java.io.File;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.UUID;

import cc.booku.owlbox.AppUpdate.DownloadService;
import cc.booku.owlbox.AppUpdate.app_version_class;
import cc.booku.owlbox.ArtDesign.SystemUtil;
import cc.booku.owlbox.BottomFragment.fragment_flv;
import cc.booku.owlbox.BottomFragment.fragment_home;
import cc.booku.owlbox.BottomFragment.fragment_notice;
import cc.booku.owlbox.BottomFragment.fragment_user;
import cc.booku.owlbox.FileOperations.FileoOperations;
import cc.booku.owlbox.InitPage.InitPage;
import cc.booku.owlbox.R;
import cc.booku.owlbox.RsaUtil.Decrypt;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;


public class FragmentManagerActivity extends AppCompatActivity {


    private List<Object> mFragmentList = new ArrayList<>();
    private FrameLayout mFlContent;
    private BottomBarLayout mBottomBarLayout;
    private RotateAnimation mRotateAnimation;
    private Handler mHandler = new Handler();
    private String filePath = Environment.getExternalStorageDirectory() + File.separator + "OwlDatabase" + File.separator;

    private String publicUrl = "http://www.shuchuwenku.vip/MavBox/";

    MyReceiver receiver = new MyReceiver();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());
        setContentView(R.layout.activity_fragment_manager);

        SystemUtil.setStatusBarColor(this, Color.parseColor("#448aca"));
        //init_initactivity();

        //initPhone();

        initView();
        initData();
        initListener();

        getfile();

        //动态申请权限
        //requestPermission();
        //初始化数据
        //initView();
        //注册广播
        // regist();

        softwareUpgrade();

    }


    private void getfile() {
        Intent intent = getIntent();

        Uri uri = intent.getData();

        if (uri != null) {

//            String scheme= uri.getScheme();
//            String host=uri.getHost();
//            String port=uri.getPort()+"";
//            String path=uri.getPath();
//            String query=uri.getQuery();


            String path = uri.getPath();
            String host = uri.getHost();
            //处理字符串：//weixing
            if (path.indexOf("external/") != -1) {
                String newpath = path.replace("external/", "storage/emulated/0/");

                //显示弹窗是否需要复制文件到本地目录
                addfileDialog(newpath);
            }
            //qq/tim
            else if (path.indexOf("external_files/") != -1) {
                String newpath = path.replace("external_files/", "");

                //显示弹窗是否需要复制文件到本地目录
                addfileDialog(newpath);

            } else {
                Toast.makeText(FragmentManagerActivity.this, "未适配路径：" + path, Toast.LENGTH_SHORT).show();

            }

            //判断文件是否符合条件


            //Toast.makeText(MainoldActivity.this, "scheme:"+scheme+"\nhost:"+host+"\nport:"+port+"\npath:"+path+"\nquery:"+query, Toast.LENGTH_SHORT).show();

        }
    }

    private void addfileDialog(final String newpath) {
        new TDialog.Builder(getSupportFragmentManager())
                .setLayoutRes(R.layout.tdialog_addfile)
                .setScreenWidthAspect(this, 0.9f)
                .setOnBindViewListener(new OnBindViewListener() {   //通过BindViewHolder拿到控件对象,进行修改
                    @Override
                    public void bindView(BindViewHolder bindViewHolder) {
                        bindViewHolder.setText(R.id.tv_filepath, newpath);
                    }
                })
                .addOnClickListener(R.id.tv_cancel, R.id.tv_confirm)
//                .setDialogAnimationRes(R.style.animate_dialog_scale)
                .setOnViewClickListener(new OnViewClickListener() {
                    @Override
                    public void onViewClick(BindViewHolder viewHolder, View view, TDialog tDialog) {

                        TextView Tv_filepath = viewHolder.getView(R.id.tv_filepath);
                        String pathcontent = Tv_filepath.getText().toString().trim();
                        switch (view.getId()) {
                            case R.id.tv_cancel:
                                tDialog.dismiss();
                                break;
                            case R.id.tv_confirm:
                                FileoOperations.copyFile(pathcontent, filePath + pathcontent.substring(pathcontent.lastIndexOf("/") + 1));
                                Toast.makeText(FragmentManagerActivity.this, "添加完成", Toast.LENGTH_SHORT).show();
                                tDialog.dismiss();
                                break;
                        }
                    }
                })
                .create()
                .show();
    }

    private void softwareUpgrade() {
//        String ProfileStr = FileoOperations.readFromSDFile(this, ProfilePath);
//        JSONObject obj = JSONObject.parseObject(ProfileStr);
//        String result = obj.getString("软件版本检查");
//        if (result.equals("yes")) {

        //动态申请权限
        requestPermission();
        //注册广播
        regist();
        //得到程序最新版本地址

        //读取配置文件信息
        try {


            String ConfigFiles_json = FileoOperations.readAssetsTxt(FragmentManagerActivity.this, "TxtData/ConfigFiles");
            JSONObject objsd = JSONObject.parseObject(ConfigFiles_json);
            String ciphertext = objsd.getString("ADDRESSCIPHER");//地址密文
            String DecryptionAddress = Decrypt.RsaDecrypt(FragmentManagerActivity.this, ciphertext);
            String appupdate = objsd.getString("APPUPDATE");

            AppVersion(DecryptionAddress + appupdate);

        } catch (Exception e) {

            Toast.makeText(FragmentManagerActivity.this, "更新地址解析错误", Toast.LENGTH_SHORT).show();
//异常处理
        }
    }


    //声明一个long类型变量：用于存放上一点击“返回键”的时刻
    private long mExitTime;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //判断用户是否点击了“返回键”
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            //与上次点击返回键时刻作差
            if ((System.currentTimeMillis() - mExitTime) > 2000) {
                //大于2000ms则认为是误操作，使用Toast进行提示
                Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                //并记录下本次点击“返回键”的时刻，以便下次进行判断
                mExitTime = System.currentTimeMillis();
            } else {
                //小于2000ms则认为是用户确实希望退出程序-调用System.exit()方法进行退出
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


    //动态申请权限
    private void requestPermission() {
        if (ContextCompat.checkSelfPermission(FragmentManagerActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(FragmentManagerActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        }
    }


    public class MyReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "app-release.apk");
            //获取权限
            try {
                Runtime.getRuntime().exec("chmod 777" + file.getCanonicalPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 由于没有在Activity环境下启动Activity,设置下面的标签
            intent = new Intent(Intent.ACTION_VIEW);
            //如果设置，这个活动将成为这个历史堆栈上的新任务的开始
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //判读版本是否在7.0以上
            if (Build.VERSION.SDK_INT >= 24) {
                //7.0以上的版本
                Uri apkUri = FileProvider.getUriForFile(context, "cc.booku.owlbox.FileProvider", file);
                //添加这一句表示对目标应用临时授权该Uri所代表的文件
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
            } else {
                //7.0以下的版本
                intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            }
            startActivity(intent);
        }
    }

    //注册广播
    private void regist() {
        IntentFilter intentFilter = new IntentFilter(DownloadService.BROADCAST_ACTION);
        intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
        LocalBroadcastManager.getInstance(this).registerReceiver(receiver, intentFilter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
    }


    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {

                case 20:
                    String res20 = msg.getData().getString("res").trim();
                    Toast.makeText(FragmentManagerActivity.this, res20, Toast.LENGTH_SHORT).show();

                    break;

            }
        }
    };


    private boolean pm(String versioncode) {

        //获取包管理者对象
        PackageManager pm = getPackageManager();

        PackageInfo info = null;
        try {
            info = pm.getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        //获取版本号和版本名称


        if (versioncode.equals(info.versionName)) {
            return false;
        } else return true;


    }


    //判断文件是否存在
    public boolean fileIsExists(String strFile) {
        try {
            File f = new File(strFile);
            if (!f.exists()) {
                return false;
            }

        } catch (Exception e) {
            return false;
        }

        return true;
    }

    private void Tupdate(final String down_url, final String title, final String filename, final String content) {

        if (fileIsExists(Environment.getExternalStorageDirectory() + File.separator + "Download" + File.separator + "app-release.apk")) {
            deleteSingleFile(Environment.getExternalStorageDirectory() + File.separator + "Download" + File.separator + "app-release.apk");
        }


        new TDialog.Builder(getSupportFragmentManager())
                .setLayoutRes(R.layout.tdialog_version_upgrde)
                .setScreenWidthAspect(this, 0.9f)
                .addOnClickListener(R.id.tv_cancel, R.id.tv_confirm)

                .setOnBindViewListener(new OnBindViewListener() {
                    public void bindView(BindViewHolder viewHolder) {
                        viewHolder.setText(R.id.tv_upgrade_content, content);
                    }
                })
                .setOnViewClickListener(new OnViewClickListener() {


                    @Override
                    public void onViewClick(BindViewHolder viewHolder, View view, TDialog tDialog) {
                        switch (view.getId()) {
                            case R.id.tv_cancel:
                                tDialog.dismiss();
                                break;
                            case R.id.tv_confirm:

                                Toast.makeText(FragmentManagerActivity.this, "如果没有弹出安装界面,请手动安装", Toast.LENGTH_SHORT).show();
                                Intent serviceIntent = new Intent(FragmentManagerActivity.this, DownloadService.class);
                                serviceIntent.setData(Uri.parse(down_url));
                                startService(serviceIntent);


                                tDialog.dismiss();
                                break;
                        }
                    }
                })
                .create()
                .show();


    }


    private void init_initactivity() {

        Intent intent = new Intent(FragmentManagerActivity.this, InitPage.class);
        startActivity(intent);

//        startActivity(new Intent(MainActivity.this, Init_Activity.class), ActivityOptions.makeSceneTransitionAnimation(MainActivity.this).toBundle());


    }


    private boolean deleteSingleFile(String filePath$Name) {
        File file = new File(filePath$Name);
        // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
        if (file.exists() && file.isFile()) {
            if (file.delete()) {
                Log.e("--Method--", "Copy_Delete.deleteSingleFile: 删除单个文件" + filePath$Name + "成功！");
                return true;
            } else {
                Toast.makeText(getApplicationContext(), "删除单个文件" + filePath$Name + "失败！", Toast.LENGTH_SHORT).show();
                return false;
            }
        } else {
            Toast.makeText(getApplicationContext(), "删除单个文件失败：" + filePath$Name + "不存在！", Toast.LENGTH_SHORT).show();
            return false;
        }
    }


    private void initUpdate(String json) {


        //http://www.shuchuwenku.vip/MavBox/statistics/version.php
        List<app_version_class> list = JSON.parseArray(json, app_version_class.class);

        for (int i = 0; i < list.size(); i++) {
            String version = list.get(i).getVersion();
            String title = list.get(i).getTitle();
            String time = list.get(i).getTime();
            String content = list.get(i).getContent();
            String down_url = list.get(i).getDown_url();
            Log.i("response===========>", version + title + time + content + down_url);
            if (pm(list.get(i).getVersion())) {

                Tupdate(down_url, title, version, content);

            }


        }


    }


    private void AppVersion(String url) {


        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                String res = response.body().string();
                //Log.i("response===========>",res);

                // Mtoast30(res);
                initUpdate(res);

            }
        });

    }


    private void initPhone() {


        //用户地理位置信息

        String TAG = "系统参数：";
        Log.e(TAG, "手机厂商：" + SystemUtil.getDeviceBrand());
        Log.e(TAG, "手机型号：" + SystemUtil.getSystemModel());
        Log.e(TAG, "手机当前系统语言：" + SystemUtil.getSystemLanguage());
        Log.e(TAG, "Android系统版本号：" + SystemUtil.getSystemVersion());
        Log.e(TAG, "手机IMEI：" + getUniquePsuedoID());

        String imei = getUniquePsuedoID();

        //2.随机获取用户ip地址
        String IPAddress = getIPAddress(this);
        HttpResponse(publicUrl + "system/statistics_phone.php?" +
                "imei=" + imei + "" +
                "&device_brand=" + SystemUtil.getDeviceBrand() + "" +
                "&system_model=" + SystemUtil.getSystemModel() + "" +
                "&system_language=" + SystemUtil.getSystemLanguage() + "" +
                "&system_version=" + SystemUtil.getSystemVersion() + "" +
                "&ip_address=" + IPAddress + "" +
                "&user_name=" + "admin" + "" +
                "&user_password=" + "123456", null);
    }
    //  http://www.shuchuwenku.vip/MavBox/system/statistics_phone.php?imei=861426389179537&device_brand=samsung&system_model=SM-G925F&system_language=zh&system_version=5.1.1&ip_address=2.2.2.2&user_name=admin&user_password=123456

    private void HttpResponse(String url, final TextView textView) {


        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, okhttp3.Response response) throws IOException {
                String res = response.body().string();
                //Log.i("response===========>",res);
                if (textView == null) {
                    Mtoast20(res);

                } else {
                    textView.setText(res);
                }

            }
        });

    }


    private void Mtoast20(String res) {
        Message msg = new Message();
        msg.what = 20;
        Bundle bundle = new Bundle();
        bundle.putString("res", res);  //往Bundle中存放数据
        msg.setData(bundle);//mes利用Bundle传递数据
        handler.sendMessage(msg);//用activity中的handler发送消息

    }


    //*********************************************************************************************

    //获得独一无二的Psuedo ID
    public String getUniquePsuedoID() {
        String serial = null;

        String m_szDevIDShort = "35" +
                Build.BOARD.length() % 10 + Build.BRAND.length() % 10 +

                Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 +

                Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 +

                Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 +

                Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 +

                Build.TAGS.length() % 10 + Build.TYPE.length() % 10 +

                Build.USER.length() % 10; //13 位

        try {
            serial = Build.class.getField("SERIAL").get(null).toString();
            //API>=9 使用serial号
            return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
        } catch (Exception exception) {
            //serial需要一个初始化
            serial = "serial"; // 随便一个初始化
        }
        //使用硬件信息拼凑出来的15位号码
        return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();

    }

    public String getIPAddress(Context context) {
        NetworkInfo info = ((ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (info != null && info.isConnected()) {
            if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//当前使用2G/3G/4G网络
                try {
                    //Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces();
                    for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                        NetworkInterface intf = en.nextElement();
                        for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                            InetAddress inetAddress = enumIpAddr.nextElement();
                            if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                                return inetAddress.getHostAddress();
                            }
                        }
                    }
                } catch (SocketException e) {
                    e.printStackTrace();
                }


            } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//当前使用无线网络
                WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());//得到IPV4地址
                return ipAddress;
            }
        } else {
//当前无网络连接,请在设置中打开网络
        }
        return null;
    }


    /**
     *      * 将得到的int类型的IP转换为String类型
     *      *
     *      * @param ip
     *      * @return
     *      
     */
    public static String intIP2StringIP(int ip) {
        return (ip & 0xFF) + "." +
                ((ip >> 8) & 0xFF) + "." +
                ((ip >> 16) & 0xFF) + "." +
                (ip >> 24 & 0xFF);
    }


    //********************************************************************************************************


    private void initView() {

        mFlContent = (FrameLayout) findViewById(R.id.fl_content);
        mBottomBarLayout = (BottomBarLayout) findViewById(R.id.bbl);

    }

    private void initData() {

        //主页
        fragment_home fragment_home = new fragment_home();
        mFragmentList.add(fragment_home);
        //分区
        fragment_flv fragment_flv = new fragment_flv();
        mFragmentList.add(fragment_flv);
        //动态
        fragment_notice fragment_notice = new fragment_notice();
        mFragmentList.add(fragment_notice);
        //消息
        fragment_user fragment_user = new fragment_user();
        mFragmentList.add(fragment_user);


        changeFragment(0); //默认显示第一页
    }

    private void initListener() {
        mBottomBarLayout.setOnItemSelectedListener(new BottomBarLayout.OnItemSelectedListener() {
            @Override
            public void onItemSelected(final BottomBarItem bottomBarItem, int previousPosition, final int currentPosition) {
                Log.i("Init_Activity", "position: " + currentPosition);

                changeFragment(currentPosition);

                if (currentPosition == 0) {
                    //如果是第一个，即首页
                    if (previousPosition == currentPosition) {
                        //如果是在原来位置上点击,更换首页图标并播放旋转动画
                        if (mRotateAnimation != null && !mRotateAnimation.hasEnded()) {
                            //如果当前动画正在执行
                            return;
                        }

                        bottomBarItem.setSelectedIcon(R.mipmap.tab_loading);//更换成加载图标 setResId

                        //播放旋转动画
                        if (mRotateAnimation == null) {
                            mRotateAnimation = new RotateAnimation(0, 360,
                                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                                    0.5f);
                            mRotateAnimation.setDuration(800);
                            mRotateAnimation.setRepeatCount(-1);
                        }
                        ImageView bottomImageView = bottomBarItem.getImageView();
                        bottomImageView.setAnimation(mRotateAnimation);
                        bottomImageView.startAnimation(mRotateAnimation);//播放旋转动画

                        //模拟数据刷新完毕
                        mHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                boolean tabNotChanged = mBottomBarLayout.getCurrentItem() == currentPosition; //是否还停留在当前页签
                                bottomBarItem.setSelectedIcon(R.drawable.tab_home_selected);//更换成首页原来选中图标
                                cancelTabLoading(bottomBarItem);
                            }
                        }, 3000);
                        return;
                    }
                }

                //如果点击了其他条目
                BottomBarItem bottomItem = mBottomBarLayout.getBottomItem(0);
                bottomItem.setSelectedIcon(R.drawable.tab_home_selected);//更换为原来的图标
                cancelTabLoading(bottomItem);//停止旋转动画
            }
        });

        mBottomBarLayout.setUnread(0, 0);//设置第一个页签的未读数为20
        mBottomBarLayout.setUnread(0, 0);//设置第二个页签的未读数
//        OkHttpClient client = new OkHttpClient();
//        Request request = new Request
//                .Builder()
//                .url("http://www.shuchuwenku.vip/today_add_video/today_add_num.php")//要访问的链接
//                .build();
//
//        Call call = client.newCall(request);
//        call.enqueue(new okhttp3.Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//
//            }
//
//            @Override
//            public void onResponse(Call call, okhttp3.Response response) throws IOException {
//                String res = response.body().string();
//                //Log.i("response===========>",res);
//
//            }
//        });

        //    mBottomBarLayout.setUnread(2, 0);//设置第一个页签的未读数为20
        //       mBottomBarLayout.setUnread(3, 0);//设置第二个页签的未读数
        // mBottomBarLayout.showNotify(2);//设置第三个页签显示提示的小红点
        // mBottomBarLayout.setMsg(3, "NEW");//设置第四个页签显示NEW提示文字
    }

    private void changeFragment(int currentPosition) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fl_content, (Fragment) mFragmentList.get(currentPosition));
        transaction.commit();
    }

    /**
     * 停止首页页签的旋转动画
     */
    private void cancelTabLoading(BottomBarItem bottomItem) {
        Animation animation = bottomItem.getImageView().getAnimation();
        if (animation != null) {
            animation.cancel();
        }
    }


}
